package com.ruoyi.system.media;

/**
 * CPC卡计费信息文件中过省信息的编码信息
 */
public class CpcProvEd {
    public static final int MSG_LEN = 23;

    /**
     * 省份行政区域编码(01-01,1,cn)
     * 样例:0x41
     */
    public byte[] nProvDat = new byte[1];

    /**
     * 本省ETC门架通行个数(02-02,1,n)
     */
    public byte[] nGanySum = new byte[1];

    /**
     * 本省累计金额(03-05,3,n)
     */
    public byte[] cLoclTol = new byte[3];

    /**
     * 本省累计计费里程(06-08,3,n)
     */
    public byte[] cMileSum = new byte[3];

    /**
     * 本省入口编码(09-11,3,bn)
     * 样例:0x432233
     */
    public byte[] cEntyHex = new byte[3];

    /**
     * 本省入口时间(12-15,4,n)UNIX时间
     */
    public byte[] cEntyTms = new byte[4];

    /**
     * 本省最新门架(16-18,3,bn)
     * 样例:0x412233
     */
    public byte[] cNewsGay = new byte[3];

    /**
     * 本省最新通过时间(19-22,4,n)UNIX时间
     */
    public byte[] cNewsTms = new byte[4];

    /**
     * 本省最新门架拟合标识(23-23,1,bn)
     * 0x00-成功; 0x01-失败
     */
    public byte[] nMachCss = new byte[1];

    /**
     * 信息编码
     *
     * @param dd
     * @return
     */
    public static CpcProvEd encoded(CpcProv dd) {
        CpcProvEd ed = new CpcProvEd();
        ed.nProvDat = ZTools.hex2bin(1, dd.nProvDat);
        ed.nGanySum = ZTools.int2bin(1, dd.nGanySum);
        ed.cLoclTol = ZTools.int2bin(3, dd.cLoclTol);
        ed.cMileSum = ZTools.int2bin(3, dd.cMileSum);
        ed.cEntyHex = ZTools.hex2bin(3, dd.cEntyHex);
        ed.cEntyTms = ZTools.int2bin(4, dd.cEntyTms);
        ed.cNewsGay = ZTools.hex2bin(3, dd.cNewsGay);
        ed.cNewsTms = ZTools.int2bin(4, dd.cNewsTms);
        ed.nMachCss = ZTools.int2bin(1, dd.nMachCss);

        return ed;
    }

    public byte[] toBytes() {
        byte[] ret = ZTools.sbMerger(nProvDat, nGanySum, cLoclTol, cMileSum, cEntyHex, cEntyTms, cNewsGay, cNewsTms, nMachCss);
        return ret;
    }

    public String toHexStr() {
        return ZTools.bin2hex(toBytes());
    }
}
